﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace ProjectStudy.App_Code.IntervalTask
{
    public class App
    {
        public static int Counter { get; set; }
        public static void Init()
        {
            var random = new Random();
            var task = IntervalTask.CreateTask(() =>
            {
                if (IntervalTask.Current.ShuttingDown)
                {
                    //如果任务被重复执行
                    return;
                }
                //在这编写自己要执行的业务
                string sql = "insert into TB_Log(description,time) values(@description,@time)";
                SqlParameter[] ps = { 
                                    new SqlParameter("@description",SqlDbType.NVarChar,50){Value="1"},
                                    new SqlParameter("@time",SqlDbType.DateTime){Value=DateTime.Now}
                                    };
                //DBAccess.ExecuteNonQuery(sql,ps);
            });
            //时间间隔
            task.SetInterval(5000);
        }

        public static void End()
        {
            IntervalTask.Current.Dispose();
        }
    }
}